function handles = moveCellUpDown(handles, direction)
% moveCellUpDown
%
% Editing:
% gs may 2005
% ------------------------------------------------------

% determine which cell to move
oldVal = get(handles.cellList, 'Value');

% which direction, if at all
maxVal = max(size(get(handles.cellList, 'String')));
switch direction
    case 'up'
        if oldVal == 1
            return
        else
            newVal = oldVal - 1;
        end
    case 'down'
        if oldVal == maxVal;
            return
        else
            newVal = oldVal + 1;
        end
    otherwise
end

% get number ID of the currently selected group
groupVal = get(handles.groupList, 'Value');

% rename as needed in the handles structure
listsAndExpts = handles.analysis.mapAverager.cellLists.currentFile.listsAndExpts;

oldList = listsAndExpts(groupVal, 2);
% celldisp(oldList)
newList = oldList;
newList{1}(newVal) = oldList{1}(oldVal);
newList{1}(oldVal) = oldList{1}(newVal);
% celldisp(newList)
listsAndExpts(groupVal, 2) = newList;

% listsAndExptsNew{newVal,1} = listsAndExpts{oldVal,1};
% listsAndExptsNew{oldVal,1} = listsAndExpts{newVal,1};
% listsAndExptsNew{newVal,2} = listsAndExpts{oldVal,2};
% listsAndExptsNew{oldVal,2} = listsAndExpts{newVal,2};
handles.analysis.mapAverager.cellLists.currentFile.listsAndExpts = listsAndExpts;

% update the listboxes
set(handles.cellList, 'String', newList{1}(:));
set(handles.cellList, 'Value', newVal);

% save
handles = saveListFile(handles);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % % % from moveGroupUpDown:
% % % 
% % % % determine which group to move
% % % oldVal = get(handles.groupList, 'Value');
% % % 
% % % % which direction, if at all
% % % maxVal = max(size(get(handles.groupList, 'String')));
% % % switch direction
% % %     case 'up'
% % %         if oldVal == 1
% % %             return
% % %         else
% % %             newVal = oldVal - 1;
% % %         end
% % %     case 'down'
% % %         if oldVal == maxVal;
% % %             return
% % %         else
% % %             newVal = oldVal + 1;
% % %         end
% % %     otherwise
% % % end
% % % 
% % % % rename as needed in the handles structure
% % % listsAndExpts = handles.analysis.mapAverager.cellLists.currentFile.listsAndExpts;
% % % listsAndExptsNew = listsAndExpts;
% % % listsAndExptsNew{newVal,1} = listsAndExpts{oldVal,1};
% % % listsAndExptsNew{oldVal,1} = listsAndExpts{newVal,1};
% % % listsAndExptsNew{newVal,2} = listsAndExpts{oldVal,2};
% % % listsAndExptsNew{oldVal,2} = listsAndExpts{newVal,2};
% % % handles.analysis.mapAverager.cellLists.currentFile.listsAndExpts = listsAndExptsNew;
% % % 
% % % % update the listboxes
% % % set(handles.groupList, 'String', listsAndExptsNew(:,1));
% % % set(handles.groupList, 'Value', newVal);
% % % handles = updateLists(handles);
% % % 
% % % % save
% % % handles = saveListFile(handles);
